//
//  CSDateFormatterMagager.m
//  CarSalesMS_GCX
//
//  Created by Tony on 2016/11/13.
//  Copyright © 2016年 Tony. All rights reserved.
//

#import "CSGXDateFormatterManager.h"


@interface CSGXDateFormatterManager ()

@end

@implementation CSGXDateFormatterManager

+ (instancetype)sharedManager {
    static id _instance;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [[self alloc] init];
        ((CSGXDateFormatterManager *)_instance).locale = [[NSLocale alloc] initWithLocaleIdentifier:@"zh_CN"];
        [(CSGXDateFormatterManager *)_instance setTimeZone:[NSTimeZone localTimeZone]];
    });
    return _instance;
}

///
- (NSString *)getWeekDayStrWithDate:(NSDate *)date {
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierRepublicOfChina];
    NSDateComponents *compo = [calendar components:NSCalendarUnitYear |
                               NSCalendarUnitMonth |
                               NSCalendarUnitDay |
                               NSCalendarUnitHour  |
                               NSCalendarUnitMinute |
                               NSCalendarUnitSecond |
                               NSCalendarUnitWeekday
                                          fromDate:date];
    NSInteger weekN = [compo weekday];
    return [self getWeekDayStr:weekN];
}

///
- (NSString *)getWeekDayStr:(NSInteger)weekN {
    NSString *str = nil;
    switch (weekN) {
        case 1:
            str = @"周日";
            break;
        case 2:
            str = @"周一";
            break;
        case 3:
            str = @"周二";
            break;
        case 4:
            str = @"周三";
            break;
        case 5:
            str = @"周四";
            break;
        case 6:
            str = @"周五";
            break;
        case 7:
            str = @"周六";
            break;
            
        default:
            break;
    }
    return str;
}


- (NSString *)currentLoneTime {
    NSDate * date = [NSDate date];
    self.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    NSString *dateStr = [self stringFromDate:date];
    NSArray *arr = [dateStr componentsSeparatedByString:@" "];
    NSString *weekStr = [self getWeekDayStrWithDate:date];
    NSString *longTime = [NSString stringWithFormat:@"%@ %@ %@", arr[0], weekStr, arr[1]];

    return longTime;
}

- (NSString *)currentTime {
    NSDate * date = [NSDate date];
    self.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    return [self stringFromDate:date];
}

- (NSString *)currentYear {
    NSDate * date = [NSDate date];
    self.dateFormat = @"yyyy";
    return [self stringFromDate:date];
}

- (NSString *)currentMonth {
    NSDate * date = [NSDate date];
    self.dateFormat = @"yyyy-MM";
    return [self stringFromDate:date];
}

- (NSString *)currentDay {
    NSDate * date = [NSDate date];
    self.dateFormat = @"yyyy-MM-dd";
    return [self stringFromDate:date];
}

- (NSString *)currentWeek {
    return [NSString stringWithFormat:@"%@ %@", [self currentDay], [self currentWeekAlone]];
}

- (NSString *)currentWeekAlone {
    NSDate *date = [NSDate date];
    self.dateFormat = @"yyyy-MM-dd HH:mm:ss";
    return [self getWeekDayStrWithDate:date];
}


+ (NSString *)getDayWithDate:(NSDate *)date {
    [CSGXDateFormatterManager sharedManager].dateFormat = @"yyyy-MM-dd";
    return [[CSGXDateFormatterManager sharedManager] stringFromDate:date];
}









#pragma mark - setter & getter

//- (void)setGx_dateFormat:(NSString *)gx_dateFormat {
//    _gx_dateFormat = gx_dateFormat;
//    
//    self.dateFormat = gx_dateFormat;
//}














@end
